define(function(require, exports, module) {
    /**
     * @class 工具类，依赖jquery。
     * @requires jquery
     */
    var $ = require("jquery"), utils = {};
    utils = {
    		
        /* 判空 */
        isEmpty:function(param) {
            if (typeof param == "object") {
            	/* 是否为数组 */
            	if((param==null) || (Object.prototype.toString.call(param)==='[object Array]' && param.length==0) || (param.hasOwnProperty('length') && param.length==0)){
            		return true;
            	}
                for (var name in param) {
                    return false;
                }
                return true;
            }
            return typeof param == "undefined" || typeof param == "string" && (param == "" || param == "undefined" || param == "0") || typeof param == "number" && (param == 0 || isNaN(param));
        },
       
        /* 获取页面宽高 */
        getBrowserWH:function() {
            var bw, bh;
            if (window.innerWidth) {
                bw = window.innerWidth;
            } else if (document.body && document.body.clientWidth) {
                bw = document.body.clientWidth;
            }
            if (window.innerHeight) {
                bh = window.innerHeight;
            } else if (document.body && document.body.clientHeight) {
                bh = document.body.clientHeight;
            }
            if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
                bh = document.documentElement.clientHeight;
                bw = document.documentElement.clientWidth;
            }
            return {
                w:bw,
                h:bh
            };
        },
       
        /* 链接跳转 */
        gotoUrl:function(url, target) {
            url = decodeURIComponent(url);
            if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) || /MSIE(\d+\.\d+);/.test(navigator.userAgent)) {
                var referLink = document.createElement("a");
                referLink.href = url;
                if (target == "_blank") {
                    referLink.target = target;
                }
                document.body.appendChild(referLink);
                referLink.click();
            } else {
                if (target == "_blank") {
                    window.open(url);
                } else {
                    location.href = url;
                }
            }
        },
        
        /* 获取url指定参数值 */
        getUrlParam:function(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            }
            return null;
        },
        
        /* 加入收藏 */
        addBookmark:function(title, url) {
            url = url || a.href;
            title = title || a.title;
            try {
                // IE
                window.external.addFavorite(url, title);
            } catch (e) {
                try {
                    // Firefox
                    window.sidebar.addPanel(title, url, "");
                } catch (e) {
                    if (/Opera/.test(window.navigator.userAgent)) {
                        // Opera
                        a.rel = "sidebar";
                        a.href = url;
                        return true;
                    }
                    alert("亲，请使用 Ctrl+D 进行添加");
                }
            }
            return false;
        }
    }
    
    //字符串方法扩展
    $.extend(String.prototype,{
    	/* trim */
		trim: function() {
	        // 用正则表达式将前后空格
	        // 用空字符串替代。
	        return this.replace(/(^\s*)|(\s*$)/g, "");
	    },
	    
	    /* replaceAll */
	    replaceAll: function(reallyDo, replaceWith, ignoreCase) {  
	        if (!RegExp.prototype.isPrototypeOf(reallyDo)) {  
	            return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);  
	        } else {  
	            return this.replace(reallyDo, replaceWith);  
	        }  
	    },
		
	    //是否为url
		isUrl: function(){
			return (new RegExp(/^[a-zA-z]+:\/\/([a-zA-Z0-9\-\.]+)([-\w .\/?%&=:]*)$/).test(this));
		},
		
		//是否为正整数
		isPositiveInteger:function(){
			return (new RegExp(/^[1-9]\d*$/).test(this));
		}
    });
    
    //数组方法扩展
	$.extend(Array.prototype,{
		/**
    	 * @name Array#max
	     * @function   
	     * @desc 返回数组中最大值。
	     */
		max: function() {
	        // 用正则表达式将前后空格
	        // 用空字符串替代。
			return Math.max.apply({},this)
	    },
	    
	    /**
    	 * @name Array#min
	     * @function   
	     * @desc 返回数组中最小值。
	     */
	    min: function() {
	    	return Math.min.apply({},this)
	    }
	    
	});
    
    /* 解决ie下indexOf兼容 */
    if (!Array.indexOf) {
        Array.prototype.indexOf = function(obj) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == obj) {
                    return i;
                }
            }
            return -1;
        };
    }
    return utils;
});